/****************************************************************************
  From Qt Examples
****************************************************************************/

#ifndef PROXYTHREAD_H
#define PROXYTHREAD_H

#include <Qt>
#include <QThread>
#include <QTcpSocket>
#include <QDebug>
#include "serverload.h"

class ProxyThread : public QThread
{
    Q_OBJECT

public:
    ProxyThread(int socketDescriptor, unsigned int simTime, double timeDenomination,
                const QString &fortune, QObject *parent);

    void run();

signals:
    void error(QTcpSocket::SocketError socketError);
    void clientMessage(QString);
    void addServer(int , QString, void*);
    void disconnectedServer(int);
    void sendLoadToProxy(int,int);
    void incomingRequest(int);

    //new
public slots:
    void readyRead();
    void disconnect();
    void sendtoServer(QString info);
    void sendTimeSync(unsigned int);
    void serverAdded(ServerLoad*, void*);
    void serverAllocated(int, QHostAddress, quint16);

private:
    ServerLoad * myModel;
    int socketDescriptor; //new
    QTcpSocket *socket; //new
    QString text;
    quint16 blockS;
    QList<QString> serverIPs;
    QList<int> serverPorts;
    QList<int> serverLoads;
    int socketType;
    bool serverFirstTime; //communicate back with the server on the first time connection
    unsigned int simTime; //set from the gui
    double timeDenomination;    //set from the gui
};

#endif
